home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / debug / clrdebug.bas next >
BASIC Source File  |  1995-01-07  |  4KB  |  114 lines

  1. Option Explicit
  2. ' MODIFIED BY   Don Blaylock 73132,1073
  3. '               Systems Analyst,
  4. '               Computer Associates, Inc.
  5. '               January 8, 1995
  6.  
  7. '
  8. 'Used in FindWindow...
  9. Declare Function GetClassName Lib "User" (ByVal hWnd As Integer, ByVal lpClassName As String, ByVal nMaxCount As Integer) As Integer
  10. Declare Function GetWindowTextLength Lib "User" (ByVal hWnd As Integer) As Integer
  11. Declare Function GetWindowText Lib "user" (ByVal hWnd As Integer, ByVal lpString As String, ByVal nMaxCount As Integer) As Integer
  12. Declare Function GetWindow Lib "user" (ByVal hWnd As Integer, ByVal wCmd As Integer) As Integer
  13. Declare Sub SetWindowPos Lib "User" (ByVal hWnd As Integer, ByVal hWndInsertAfter As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer)
  14.  
  15.  
  16. Global Const GW_CHILD = 5
  17. Global Const GW_HWNDFIRST = 0
  18. Global Const GW_HWNDLAST = 1
  19. Global Const GW_HWNDNEXT = 2
  20. Global Const GW_HWNDPREV = 3
  21. Global Const GW_OWNER = 4
  22. Declare Function SetFocusAPI Lib "User" Alias "SetFocus" (ByVal hWnd As Integer) As Integer
  23. '
  24. 'Used in GetWinClassName...
  25. Declare Function GetClassName Lib "User" (ByVal hWnd As Integer, ByVal lpClassName As String, ByVal nMaxCount As Integer) As Integer
  26.  
  27. Function FindWindow (strCaption As String, intParmType As Integer) As Integer
  28. '-------------------------------------------------------------------------
  29. 'Author:        Barry Seymour, Marquette Computer Consultants
  30.  
  31. 'Date:          December 29, 1992   15:53
  32. 'Global Vars:   CLASSNAME, CAPTIONTEXT (in LIB_API.BAS)
  33. 'Form Vars:
  34. 'Subs:
  35. 'Functions:
  36. 'Returns:       0 if fails; hWnd of sought window if succeeds.
  37. 'Explanation:  ----------------------------------------------------------------
  38. 'Function checks all active windows and returns the handle of the FIRST
  39. 'window containing the sought caption or classname.  It returns zero if
  40. 'there are no windows found.
  41.  
  42. ' MODIFIED BY   Don Blaylock 73132,1073
  43. '               Systems Analyst,
  44. '               Computer Associates, Inc.
  45. '               January 8, 1995
  46.  
  47. Dim strTest As String
  48. Dim intTxtLen As Integer
  49. Dim intThisHandle As Integer
  50.  
  51.     Const CAPTIONTEXT = 1
  52.     Const CLASSNAME = 2
  53.     
  54.     strCaption = UCase$(strCaption) ' ensure case insensitivity
  55.     FindWindow = 0 ' initialize return value
  56.  
  57.     '1. Traverse the list of all active windows
  58.     DoEvents
  59.     
  60.     intThisHandle = GetWindow(Screen.ActiveForm.hWnd, GW_HWNDFIRST)
  61.  
  62.     Do While intThisHandle <> 0
  63.  
  64.     If intParmType = CAPTIONTEXT Then
  65.         intTxtLen = GetWindowTextLength(intThisHandle) 'Get the window caption length
  66.         If intTxtLen > 0 Then ' is it a sought window?
  67.         strTest = Space$(intTxtLen + 2)
  68.         intTxtLen = GetWindowText(intThisHandle, strTest, intTxtLen + 2)
  69.         strTest = Left$(UCase$(strTest), intTxtLen)
  70.         End If ' if intTxtLen > 0
  71.     ElseIf intParmType = CLASSNAME Then
  72.         strTest = UCase$(GetWinClassName(intThisHandle))
  73.     End If
  74.  
  75.     If InStr(strTest, strCaption) Then ' you found the window you wanted!
  76.         FindWindow = intThisHandle
  77.         Exit Function
  78.     End If
  79.  
  80.     ' Get the next task list item in the master list.
  81.     intThisHandle = GetWindow(intThisHandle, GW_HWNDNEXT)
  82.  
  83.     DoEvents ' Process Windows events.
  84.     Loop
  85.  
  86.     'if you get this far, no windows were found meeting your.
  87.     'caption criteria.  Function returns zero.
  88.  
  89. End Function
  90.  
  91. Function GetWinClassName (hWnd As Integer) As String
  92. ' MODIFIED BY   Don Blaylock 73132,1073
  93. '               Systems Analyst,
  94. '               Computer Associates, Inc.
  95. '               January 8, 1995
  96.  
  97. Const MAX = 255
  98. Dim strReturn As String
  99. Dim intResult As Integer
  100. Dim strResult As String
  101.  
  102.     strReturn = Space$(MAX)
  103.  
  104.     intResult = GetClassName(hWnd, strReturn, MAX)
  105.     
  106.     If intResult <> 0 Then
  107.     strResult = Trim$(strReturn) ' TRIM OUT BLANKS
  108.     strResult = Left$(strResult, Len(strResult) - 1) ' REMOVE CHR$(0) FROM END
  109.     GetWinClassName = strResult
  110.     End If
  111.  
  112. End Function
  113.  
  114.